package com.dz.common.core.entity;


import com.dz.common.core.entity.listener.EntityListener;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicUpdate;
import org.springframework.data.annotation.CreatedBy;
import org.springframework.data.annotation.CreatedDate;
import org.springframework.data.annotation.LastModifiedBy;
import org.springframework.data.annotation.LastModifiedDate;

import javax.persistence.*;
import java.util.Date;

@Setter
@Getter
@MappedSuperclass
@EntityListeners(EntityListener.class)
@DynamicUpdate
public abstract class BaseEntity<T> extends Entity<T> {

	/** 乐观锁版本. */
	@Version
	@Column(name = "version")
	private Integer version;

	/** 创建者. */
	@CreatedBy
	@Column(name = "creator")
	private Long creator;

	/** 创建时间. */
	@CreatedDate
	@Column(name = "create_time", updatable = false)
	@Temporal(TemporalType.TIMESTAMP)
	private Date createTime;

	/** 更新者. */
	@LastModifiedBy
	@Column(name = "updater")
	private Long updater;

	/** 更新时间. */
	@LastModifiedDate
	@Column(name = "update_time")
	@Temporal(TemporalType.TIMESTAMP)
	private Date updateTime;

	/** 删除标志. */
	@Column(name = "delete_flag")
	private Integer deleteFlag;
}
